package com.fayuan.nocv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fayuan.nocv.dao.IndexMapper;
import com.fayuan.nocv.entity.NocvData;
import com.fayuan.nocv.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IndexServiceImpl extends ServiceImpl<IndexMapper, NocvData> implements IndexService {

    @Autowired
    private IndexMapper indexMapper;
    @Override
    public List<NocvData> queryPie() {


        List<NocvData> nocvData = indexMapper.lastChinaMapData();

        return nocvData;
    }

    @Override
    public Map<String, List<Object>> queryBar() {

        List<NocvData> nocvData = this.queryPie();
        List<String>cities = new ArrayList<>();
        for (NocvData data : nocvData) {
            cities.add(data.getName());
        }
        List<Integer>values = new ArrayList<>();
        for (NocvData data : nocvData) {
            values.add(data.getValue());
        }
        Map resultMap = new HashMap<>();
        resultMap.put("cities",cities);
        resultMap.put("vals",values);
        return resultMap;
    }

    @Override
    public List<NocvData> lastChinaMapData() {

        return indexMapper.lastChinaMapData();
    }
}
